/*
 * Created on May 3, 2004 by mreynolds
 */
package cn.com.sd.common.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.collections.Transformer;


/**
 * This is useful for performing case-insensitive sorting using the commons package.
 * Here is an example of how this class can be used:
 * <code>
 * Comparator xformComparator = new TransformingComparator(new ToUpperTransformer(), new NullComparator());
 * Comparator comparator = new BeanComparator("firstName", xformComparator);
 * </code>
 * in the above comparator, the firstName property of the bean being compared is transformed to uppercase
 * and nullsafe.
 * The collection's properties are not actually transformed to uppercase - but the comparator does a case-insenstive sorting.
 *  
 * <br><br>
 * Copyright &copy;2004 Integral7, Inc.  All rights reserved.
 * @author mreynolds
 * @version $Header: /usr/local/cvsroot/pueblo/src/com/integral7/util/ToUpperTransformer.java,v 1.4 2006/04/11 19:18:42 kkokal Exp $
 */
public class TransformerChain implements Transformer {
    List<Transformer> transformers = new ArrayList<Transformer>();
    /**
     * no-arg constructor
     */
    public TransformerChain(Transformer... transformers) {
        super();
        this.transformers = Arrays.asList(transformers);
    }

    /**
     * converts the incoming string to uppercase
     * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
     */
    public Object transform( Object arg0 ) {
        
        for(Transformer t : transformers){
            arg0 = t.transform(arg0);
        }
        return arg0;
    }
    
}
